class_name VFXSystem
extends BaseSystem

## VFX管理系统

#region 属性
@export var vfx_infos:Array[VFXInfo]
var vfx_dict:Dictionary = {}
var last_play_id:int = 0
var vfx_player_dict:Dictionary = {}
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
func init_system(args = null):
	super(args)
	for info:VFXInfo in vfx_infos:
		if not vfx_dict.has(info.id):
			vfx_dict[info.id] = info
#endregion
#region 公共方法
## rotation：弧度制
func play_vfx_by_id(vfx_id:String,duration:float,target:Node = null,is_attached:bool = false,offest:Vector2 = Vector2.ZERO,rotation:float = 0) -> int:
	if not vfx_dict.has(vfx_id):
		push_error("没有vfx_id:{0} 对应的vfx".format([vfx_id]))
	var vfx_info:VFXInfo = vfx_dict[vfx_id].duplicate(true)
	vfx_info.init(last_play_id,duration,target,is_attached,offest,rotation)
	last_play_id += 1
	var vfx_player:VFXPlayer = VFXPlayer.new(vfx_info)
	vfx_player_dict[vfx_info.play_id] = vfx_player
	var vfx = vfx_info.vfx_scene.instantiate()
	vfx_player.add_child(vfx)
	vfx_player.position += offest
	vfx_player.rotate(rotation)
	if is_attached and target:
		target.add_child(vfx_player)
	else:
		GameVFXSystem.add_child(vfx_player)
	vfx_player.play()
	return vfx_info.play_id
func play_vfx_by_info(temp_vfx_info:VFXInfo,duration:float,target:Node = null,is_attached:bool = false,offest:Vector2 = Vector2.ZERO,rotation:float = 0) -> int:
	var vfx_info:VFXInfo = temp_vfx_info.duplicate(true)
	vfx_info.init(last_play_id,duration,target,is_attached,offest,rotation)
	last_play_id += 1
	var vfx_player:VFXPlayer = VFXPlayer.new(vfx_info)
	vfx_player_dict[vfx_info.play_id] = vfx_player
	var vfx = vfx_info.vfx_scene.instantiate()
	vfx_player.add_child(vfx)
	vfx_player.position += offest
	vfx_player.rotate(rotation)
	if is_attached and target:
		target.add_child(vfx_player)
	else:
		GameVFXSystem.add_child(vfx_player)
	vfx_player.play()
	return vfx_info.play_id
func stop_vfx(vfx_play_id:int):
	var vfx_player:VFXPlayer = vfx_player_dict.get(vfx_play_id)
	if vfx_player:
		vfx_player.stop()
		vfx_player_dict.erase(vfx_play_id)
func get_vfx_info(vfx_id:String) -> VFXInfo:
	return vfx_dict.get(vfx_id)
func get_vfx_player(vfx_play_id:int) -> VFXPlayer:
	return vfx_player_dict.get(vfx_play_id)
#endregion
#endregion
#region 私有方法
#endregion
#region 生命周期函数
#endregion
